package logic

import (
	"context"
	"server/models"
	"server/proto"
)

// todo: 生成订单
func (s *ServerRpc) CreateOrder(ctx context.Context, in *proto.CreateOrderReq) (*proto.CreateOrderRes, error) {
	id := models.UUidInit()
	order, err := models.CreateOrder(models.Order{
		Userid:      int(in.Userid),
		OrderSn:     id,
		GoodsCount:  float64(in.Count),
		OrderStatus: 1,
	})
	if err != nil {
		return &proto.CreateOrderRes{
			OrderSn: "",
		}, err
	}
	return &proto.CreateOrderRes{
		OrderSn: order.OrderSn,
	}, nil
}
